﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Security.Cryptography;
using Reversi;

public partial class Login : System.Web.UI.Page
{
    private static readonly DataSourceDataContext db = new DataSourceDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        global::User u = Reversi.DataAccessLayer.CheckCredentials(txtUsername.Text, txtPassword.Text, true);
        
        if (u != null)
        {
            Session["SessionID"] = u.sessionid;
            //lblLoginMessage.Text = "Logged in with sessionid=" + u.sessionid;
            Response.Redirect("Game.aspx");
        }
        else
        {
            lblLoginMessage.Text = "Invalid Username or Password.";
        }
    }
    protected void btnRegister_Click(object sender, EventArgs e)
    {
        string error = DataAccessLayer.CreateUser(txtUsername.Text, txtPassword.Text);
        if (error == null)
        {
            lblLoginMessage.Text = "Created User, please login.";
        }
        else
        {
            lblLoginMessage.Text = error;
        }
    }
}
